package com.cws4cloud.cws.sdAdmin.biz.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cws4cloud.cws.common.core.util.R;
import com.cws4cloud.cws.common.log.annotation.SysLog;
import com.cws4cloud.cws.sdAdmin.api.entity.SysWebsiteConfig;
import com.cws4cloud.cws.sdAdmin.api.service.SysWebsiteConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 站点设置
 *
 * @author zhulj
 * @date 2021-03-05 15:07:23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/syswebsiteconfig" )
@Api(value = "syswebsiteconfig", tags = "站点设置管理")
public class SysWebsiteConfigController {

    private final  SysWebsiteConfigService sysWebsiteConfigService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysWebsiteConfig 站点设置
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('syswebsiteconfig_get')" )
    public R getSysWebsiteConfigPage(Page page, SysWebsiteConfig sysWebsiteConfig) {
        return R.ok(sysWebsiteConfigService.page(page, Wrappers.query(sysWebsiteConfig)));
    }


    /**
     * 通过id查询站点设置
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('syswebsiteconfig_get')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(sysWebsiteConfigService.getById(id));
    }

    /**
     * 新增站点设置
     * @param sysWebsiteConfig 站点设置
     * @return R
     */
    @ApiOperation(value = "新增站点设置", notes = "新增站点设置")
    @SysLog("新增站点设置" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('syswebsiteconfig_add')" )
    public R save(@RequestBody SysWebsiteConfig sysWebsiteConfig) {
        return R.ok(sysWebsiteConfigService.save(sysWebsiteConfig));
    }

    /**
     * 修改站点设置
     * @param sysWebsiteConfig 站点设置
     * @return R
     */
    @ApiOperation(value = "修改站点设置", notes = "修改站点设置")
    @SysLog("修改站点设置" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('syswebsiteconfig_edit')" )
    public R updateById(@RequestBody SysWebsiteConfig sysWebsiteConfig) {
        return R.ok(sysWebsiteConfigService.updateById(sysWebsiteConfig));
    }

    /**
     * 通过id删除站点设置
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除站点设置", notes = "通过id删除站点设置")
    @SysLog("通过id删除站点设置" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('syswebsiteconfig_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(sysWebsiteConfigService.removeById(id));
    }

}
